var N = ["一", "二", "三", "四", "五", "六", "七", "八", "九","十"];
//自定义漏斗 ios android 选择版本号
function changeVersion(obj){
	var platForm = $(obj).val();
	if(platForm == "ios" || platForm == "android"){
		$("#funnel_app_version").parent(".form-group").show();
		$('.chosen-select').chosen("destroy").chosen();
		$('.chosen-select-deselect').chosen({ allow_single_deselect: true });
		$.ajax({
			url : contextPath+'/traffic/appVersion',
			type : "POST",
			data : {
				platForm : platForm
			},
			success:function(data) {
				if(data && data.msg != null) {
					var list = data.msg;
					list.sort(function(a, b) {return a.name > b.name});
					var html = '<option value="">全部</option>';
					for(var i=0;i<list.length;i++){
						html += '<option value="'+list[i].value+'">'+list[i].name+'</option>';
					}
					$("#funnel_app_version").html(html);
					$('#funnel_app_version').chosen("destroy").chosen();
				}
			},
			error:function(data) {
			}
		});
	}else{
		$("#funnel_app_version").parent(".form-group").hide();
	}
}


//自定义漏斗  新增
function newFunnel(){
	$("#funnelLabel").html("新增漏斗");
	$(".funelcop input").each(function () {
		$(this).val("");
		$(this).attr("pageCode","");
	});
	$("#funnelId").val("");
	$("#funnelName").val("");
	$("#step1").show();
	$("#step2").hide();
	$("#step3").hide();
	$("#update").click();
	$("input[name=funnelType]").attr("disabled", false);
	$("#save").attr("onclick","showNextStep()");
	$("#saveFunnelBUtton").attr("onclick","saveFunnel('')");
	if($(".funnelstep li").length < 3){
		var num = parseInt($(".funnelstep li:last-child").attr("data-index"));
		var str = "";
		for(var i =0;i<3-num;i++){
			str += "<li class='liSteps dragable' data-index='"+(num+1)+"' style='z-index: 990; position: inherit;' onmouseover='showSetting(this)'>" +
				"<div class='step-handle'><span class='ace-icon glyphicon glyphicon-th' style='color:#91d9fa;top:25px;left:6px'></span></div>" +
				"<div class='step-container'><div class='funnelstepname funnelSteps'>步骤"+N[num+1]+"：</div>" +
				"<div class='funnelstepcont'><div class='funelcop' style='position: relative;'>" +
				"<input type='text' readonly='readonly' id='setValue"+ (num+2) +"' pageCode='' style='border-radius: 3px!important;border: 0px;background-color: white!important;'></div></div>" +
				"<div id='prompt-box' class='widget-toolbar' style='border-radius:10px;'><a href='javascript:deleteStep();' data-action='close'>" +
				"<i class='ace-icon fa fa-times' style='color:gray;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
				"<a href='javascript:editTwoStep();' data-action='settings'>" +
				"<i class='ace-icon fa fa-cog' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
				"<a href='javascript:addStep();' data-action='collapse'>" +
				"<i class='ace-icon fa fa-plus' data-icon-show='fa-plus' data-icon-hide='fa-minus' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
				"</div></div></li>";
			num++;
		}
		$(".funnelstep").append(str);
	}
}

function showNextStep(){
	var funnelName = $("#funnelName").val();
	if(funnelName == ""){
		showMsg("漏斗名称不能为空");
		return false;
	}
	$("#funnelTitle").html(funnelName);
	var type = $("#funnelTypeText").val();
	var funnelType = $("input[name='funnelType']:checked").val();
	$.ajax({
		url : contextPath+'/traffic/selectFunnel',
		type : "POST",
		data :{"name":funnelName,"funnelType":funnelType},
		success:function(data) {
			if(data != null && data.funnel != null){
				showMsg("漏斗已存在");
			}else{
				if(type != "" && type != funnelType){
					$(".funnelstep .funelcop input").each(function () {
						$(this).val("");
						$(this).attr("pageCode","");
					});
					$("#pageName").val("3PinDsyw_首页");
					$("#pindaoSelect").hide();
				}
				if(funnelType == "品类"){
					$("#categoryDiv").show();
					$("#productDiv").hide();
				}else{
					$("#productDiv").show();
					$("#categoryDiv").hide();
				}
				$("#funnelTypeText").val(funnelType);
				$("#step1").hide();
				$("#step2").show();
				$("#step3").hide();
				if(funnelType == "品类"){
					$.ajax({
						url : contextPath+'/traffic/getAllCategory',
						type : "POST",
						success:function(data) {
							$("#categoryId").html("");
							if(data != null && data.categoryMap != null){
								var str = "";
								var categoryMap = data.categoryMap;
								$.each(categoryMap,function(key,value){
									str += "<option value = '"+value+"'>"+value+"</option>";
								});
								$("#categoryId").html(str);
							}
						}
					});
				}
			}
		}
	});
}
function editFunnel(funnelId,funnelName,funnelType){
	$("#funnelLabel").html("编辑漏斗");
	$("#funnelId").val(funnelId);
	$("#funnelName").val(funnelName);
	$("#step1").show();
	$("#step3").hide();
	$("#step2").hide();
	$("#update").click();
	$("input[name=funnelType]").attr("disabled", false);
	if(funnelType == "0"){
		$("#category").click();
	}else{
		$("#product").click();
	}
	$("input[name=funnelType]").attr("disabled", true);
	$("#save").attr("onclick","showFunnelStep("+funnelId+")");
	$("#saveFunnelBUtton").attr("onclick","saveFunnel("+funnelId+")");
}

function showFunnelStep(funnelId){
	$.ajax({
		url : contextPath+'/traffic/getFunnelDetailList',
		type : "POST",
		data : {"funnelId":funnelId,"name":$("#funnelName").val()},
		success:function(data) {
			if(data != null && data.funnelDetailList != null){
				var funnelDetailList = data.funnelDetailList;
				var str = "";
				for(var i=0;i<funnelDetailList.length;i++){
					var param = "";
					var pageName = funnelDetailList[i].pageName;
					if(funnelDetailList[i].funnelType == "品类"){
						param = pageName + "_" + funnelDetailList[i].categoryName;
					}else{
						param = pageName + "_" + funnelDetailList[i].paramId;
					}
					str += "<li class='liSteps dragable' data-index='"+i+"' style='z-index: 990; position: inherit;' onmouseover='showSetting(this)'>" +
						"<div class='step-handle'><span class='ace-icon glyphicon glyphicon-th' style='color:#91d9fa;top:25px;left:6px'></span></div>" +
						"<div class='step-container'><div class='funnelstepname funnelSteps'>步骤"+N[i]+"：</div>" +
						"<div class='funnelstepcont'><div class='funelcop' style='position: relative;'>" +
						"<input type='text' readonly='readonly' id='setValue"+ (i+1) +"' pageCode='"+funnelDetailList[i].pageCode+"' value='"+param+"' style='border-radius: 3px!important;border: 0px;background-color: white!important;'></div></div>" +
						"<div id='prompt-box' class='widget-toolbar' style='border-radius:10px;'><a href='javascript:deleteStep();' data-action='close'>" +
						"<i class='ace-icon fa fa-times' style='color:gray;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
						"<a href='javascript:editTwoStep();' data-action='settings'>" +
						"<i class='ace-icon fa fa-cog' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
						"<a href='javascript:addStep();' data-action='collapse'>" +
						"<i class='ace-icon fa fa-plus' data-icon-show='fa-plus' data-icon-hide='fa-minus' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
						"</div></div></li>";
				}
				$("#funnelTypeText").val(funnelDetailList[0].funnelType);
				$("#funnelTitle").html(funnelDetailList[0].name);
				if(funnelDetailList[0].funnelType == "品类"){
					$("#categoryDiv").show();
					$("#productDiv").hide();
				}else{
					$("#productDiv").show();
					$("#categoryDiv").hide();
				}
				$(".funnelstep").html("");
				$(".funnelstep").html(str);
				$("#step1").hide();
				$("#step2").show();
				$("#step3").hide();
				if(funnelDetailList[0].funnelType == "品类"){
					$.ajax({
						url : contextPath+'/traffic/getAllCategory',
						type : "POST",
						success:function(data) {
							$("#categoryId").html("");
							if(data != null && data.categoryMap != null){
								var str = "";
								var categoryMap = data.categoryMap;
								$.each(categoryMap,function(key,value){
									str += "<option value = '"+value+"'>"+value+"</option>";
								});
								$("#categoryId").html(str);
							}
						}
					});
				}
			}
		}
	});
}

function editTwoStep(){
	var num = parseInt($(".funnelstep .selected").attr("data-index"));
	$("#stepTitle").html("设置步骤"+N[num]);
	$("#flag").val(num+1);
	var type = $("#funnelTypeText").val();
	var value = $(".funnelstep .selected .funelcop input").val();
	var pageCode = $(".funnelstep .selected .funelcop input").attr("pageCode");
	if(value != ""){
		if(pageCode.indexOf("3PinD") > -1 && pageCode != "3PinDsyw" && type == "产品"){
			if($("#pinDao option").length == 0){
				$.ajax({
					url: contextPath+'/traffic/getPindaoParent',
					type: "POST",
					success: function (data) {
						$("#pinDao").html("");
						if (data != null && data.statisticCodeList != null) {
							var str = "";
							var statisticList = data.statisticCodeList;
							for (var i = 0; i < statisticList.length; i++) {
								str += "<option value = '" + statisticList[i].code + "_" + statisticList[i].name + "频道页'>" + statisticList[i].name + "</option>";
							}
							$("#pinDao").html(str);
						}
					}
				});
			}
			$("#pindaoSelect").show();
			$("#pageName").val("3PinD_频道页");
			$("#pinDao").val(pageCode+ "_"+ value.split("_")[0]);
		}else{
			$("#pageName").val(pageCode+ "_"+ value.split("_")[0]);
			$("#pindaoSelect").hide();
		}
		if(value.indexOf("频道页") > -1) {
			$("#pageName").val("3PinD_频道页");
		}
		if(type == "品类"){
			$("#categoryId").val(value.split("_")[1]);
		}else {
			$("#productId").val(value.split("_")[1]);
		}
	}
	$("#step3").slideDown("slow");
	$('.modal').on('show.bs.modal', centerModals);
	$(window).on('resize', centerModals);
}

function deleteStep(){
	var num = parseInt($(".funnelstep .selected").attr("data-index"));
	$(".funnelstep .selected").remove();
	var n = num - 1;
	var obj;
	if(n < 0){
		obj = $(".liSteps");
	}else{
		obj = $(".liSteps:gt("+n+")");
	}
	obj.each(function(){
		$(this).attr("data-index",num);
		var value = $(this).find(".funelcop input").val();
		$(this).find(".funnelstepname").html("步骤"+N[num]+"：");
		$(this).find(".funelcop input").attr("id","setValue"+(num+1));
		num++;
	});
}

function showSetting(obj){
	$(".step-handle span").css("color","#91d9fa");
	$(obj).find(".step-handle span").css("color","#00a0ea");
	$(".funnelstep li").removeClass("selected");
	$(obj).addClass("selected");
}

function addStep(){
	var num = parseInt($(".funnelstep .selected").attr("data-index"));
	var lastTr = parseInt($(".funnelstep li:last-child").attr("data-index"));
	var str = "<li class='liSteps dragable' data-index='"+(num+1)+"' style='z-index: 990; position: inherit;' onmouseover='showSetting(this)'>" +
		"<div class='step-handle'><span class='ace-icon glyphicon glyphicon-th' style='color:#91d9fa;top:25px;left:6px'></span></div>" +
		"<div class='step-container'><div class='funnelstepname funnelSteps'>步骤"+N[num+1]+"：</div>" +
		"<div class='funnelstepcont'><div class='funelcop' style='position: relative;'>" +
		"<input type='text' readonly='readonly' id='setValue"+ (num+2) +"' pageCode='' style='border-radius: 3px!important;border: 0px;background-color: white!important;'></div></div>" +
		"<div id='prompt-box' class='widget-toolbar' style='border-radius:10px;'><a href='javascript:deleteStep();' data-action='close'>" +
		"<i class='ace-icon fa fa-times' style='color:gray;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
		"<a href='javascript:editTwoStep();' data-action='settings'>" +
		"<i class='ace-icon fa fa-cog' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
		"<a href='javascript:addStep();' data-action='collapse'>" +
		"<i class='ace-icon fa fa-plus' data-icon-show='fa-plus' data-icon-hide='fa-minus' style='color:#269abc;font:normal normal normal 20px/1 FontAwesome'></i></a>" +
		"</div></div></li>";
	if(lastTr < 9){
		$(str).insertAfter($(".funnelstep li").eq(num));
		var n = num+1;
		$(".liSteps:gt("+n+")").each(function(){
			++n;
			var value = $(this).find(".funelcop input").val();
			$(this).attr("data-index",n);
			$(this).find(".funnelstepname").html("步骤"+N[n]+"：");
			$(this).find(".funelcop input").attr("id","setValue"+(n+1));
		});
	}
}

function selectPindao(obj){
	var type = $("#funnelTypeText").val();
	var pageName = $(obj).val();
	if(pageName.split("_")[0].indexOf("3PinD") >-1 && pageName.split("_")[0] != "3PinDsyw"){
		if(type == "产品") {
			if($("#pinDao option").length == 0){
				$.ajax({
					url: contextPath+'/traffic/getPindaoParent',
					type: "POST",
					success: function (data) {
						$("#pinDao").html("");
						if (data != null && data.statisticCodeList != null) {
							var str = "";
							var statisticList = data.statisticCodeList;
							for (var i = 0; i < statisticList.length; i++) {
								str += "<option value = '" + statisticList[i].code + "_" + statisticList[i].name + "频道页'>" + statisticList[i].name + "</option>";
							}
							$("#pinDao").html(str);
						}
					}
				});
			}
			$("#pindaoSelect").show();
		}else if(type == "品类"){
			$.ajax({
				url : contextPath+'/traffic/getPindaoCode',
				type : "POST",
				data : {"name":$("#categoryId").val()},
				success:function(data) {
					if(data != null && data.statisticCode != null){
						$("#pinDaoCode").val(data.statisticCode.code+"_频道页");
					}
				}
			});
			$("#pindaoSelect").hide();
		}
	}else{
		$("#pindaoSelect").hide();
	}
}

function selectPageName(obj){
	var type = $("#funnelTypeText").val();
	if(type == "品类") {
		$.ajax({
			url : contextPath+'/traffic/getPindaoCode',
			type : "POST",
			data : {"name":$(obj).val()},
			success:function(data) {
				if(data != null && data.statisticCode != null){
					if($(obj+" option[value=3PinD_频道页]").length == 0){
						var str = "var str = <option value = '3PinD_频道页'>频道页</option>";
						$(str).insertAfter($(obj+" option").eq(0));
					}else{
						$("#pinDaoCode").val(data.statisticCode.code+"_频道页");
					}

				}else{
					$(obj+"option[value=3PinD_频道页]").remove();
				}
                $('.chosen-select').chosen("destroy").chosen();
                $('.chosen-select-deselect').chosen({ allow_single_deselect: true });
			}
		});
	}
}

function saveStep(){
	var type = $("#funnelTypeText").val();
	var pageName = $("#pageName").val();
	if(pageName.indexOf("频道页") > -1 && type == "产品"){
		pageName = $("#pinDao").val();
	}else if(pageName.indexOf("频道页") > -1 && type == "品类"){
		pageName = $("#pinDaoCode").val();
	}
	var comb_value = "";
	if(type == "品类"){
		var categoryId = $("#categoryId").val();
		comb_value = pageName.split("_")[1] + "_"+ categoryId;
	}else{
		var productId = $("#productId").val();
		comb_value = pageName.split("_")[1] + "_"+ productId;
	}
	var flag = $("#flag").val();
	$("#setValue" + flag).val(comb_value);
	$("#setValue" + flag).attr("pageCode",pageName.split("_")[0]);
	$("#step3").hide();
}

function saveFunnel(funnelId){
	var j = {};
	var type = $("#funnelTypeText").val();
	j.funnelId = funnelId;
	j.name = $("#funnelTitle").html();
	j.funnelType = type;
	j.list = [];
	for(var i=1;i<=$(".funnelstep li").length;i++){
		var str = $("#setValue"+i).val();
		if(str == ""){
			showMsg("请设置步骤"+i);
			return null;
		}
		var pageName = str.split("_")[0];
		var categoryName = str.split("_")[1];
		var pageCode = $("#setValue"+i).attr("pageCode");
		j.list.push({pageName:pageName,categoryName:categoryName,stepIndex:i,pageCode:pageCode});
	}
	$.ajax({
		url : contextPath+'/traffic/savaFunnel',
		data : {"jsondata" : JSON.stringify(j)},
		type : "POST",
		success: function(json) {
			$(".close").click();
			searchClick7("1","10");
			if(funnelId != ""){
				viewFunnel(funnelId);
			}
		}
	});
}
var flag = true;
function viewFunnel(funnelId){
	if(flag){
		flag = false;
		$("#funnelTable a").each(function(){
			if($(this).attr("funnelId") != '' && $(this).attr("funnelId") != undefined){
				$(this).css("color","#428bca");
			}
			if($(this).attr("funnelId") == funnelId){
				$(this).css("color","#d6487e");
			}
		});
		$("#funnelId").val(funnelId);
		var chooseTime = $("#config-demo9").val();
		var platform = $("#funnel_plat_form").val();
		var app_version = $("#funnel_app_version").val();
		if(app_version != "" && app_version != null){
			platform = null;
		}
		var visitType = $("input[name=interview_type]:checked").val();
		$("#funnelTable").attr("class","col-xs-6");
		$("#chartDiv").show();
		$.ajax({
			url: contextPath + '/traffic/getFunnelChart',
			data: {
				// "chooseTime": chooseTime,
				"beginDate":chooseTime.split("-")[0].trim(),
				"endDate":chooseTime.split("-")[1].trim(),
				"platform": platform,
				"version": app_version,
				"visitType": visitType,
				"funnelId": funnelId
			},
			type: "POST",
			beforeSend: function () {
				openPartialLayer($("#chartDiv"));
			},
			complete: function () {
				removeLoading($("#chartDiv"));
				flag = true;
			},
			success: function (data) {
				if (data != null && data.funnelDetailList != null) {
					$(".title_funnel").html(data.funnelName);
					var str = [];
					for (var i = 0; i < data.funnelDetailList.length; i++) {
						var name = data.funnelDetailList[i].pageName;
						if(data.funnelDetailList[i].amount > 0){
							if(data.funnelDetailList[i].funnelType == "0"){
								name = data.funnelDetailList[i].categoryName + data.funnelDetailList[i].pageName;
							}
							str.push({name: name, value: data.funnelDetailList[i].amount});
						}
					}
					yDataAmonut1 = str;
					funnelModal(yDataAmonut1,'funnelDetail','name','value',visitType,500);
				}
			}
		});
	}
}

var active_class = 'active';
$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
	var th_checked = this.checked;//checkbox inside "TH" table header
	$(this).closest('table').find('tbody > tr').each(function(){
		var row = this;
		if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
		else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
	});
});

$('#simple-table').on('click', 'td input[type=checkbox]' , function(){
	var $row = $(this).closest('tr');
	if($row.is('.detail-row ')) return;
	if(this.checked) $row.addClass(active_class);
	else $row.removeClass(active_class);
});

function showTip(e,content,ifhave){
	if(ifhave==null || ifhave=='0')return;
	var div1 = document.getElementById(content); //将要弹出的层
	var x,x1;
	var y,y1;
	if(window.event){
		e = window.event;
		x=(e.clientX+document.body.scrollLeft+10); //鼠标目前在X轴上的位置，加10是为了向右边移动10个px方便看到内容
		y=(e.clientY+document.body.scrollTop+6);
		//if((x+400) > document.body.clientWidth){x=x-400;}
		//if((y+150) > document.body.clientHeight){y=y-150-6;}
	}else{
		x=(e.pageX+10); //鼠标目前在X轴上的位置，加10是为了向右边移动10个px方便看到内容
		y=(e.pageY+6);
		//if((x+400) > document.body.clientWidth){x=x-400;}
		//if((y+150) > document.body.clientHeight){y=y-150-6;}
	}

	div1.style.left=x+"px" ; //鼠标目前在X轴上的位置，加10是为了向右边移动10个px方便看到内容
	div1.style.top=y+"px";
	div1.style.display= "block" ; //div1初始状态是不可见的，设置可为可见
	//window.event代表事件状态，如事件发生的元素，键盘状态，鼠标位置和鼠标按钮状.
	//clientX是鼠标指针位置相对于窗口客户区域的 x 坐标，其中客户区域不包括窗口自身的控件和滚动条。
	div1.style.position= "absolute" ; //必须指定这个属性，否则div1层无法跟着鼠标动
}


function searchClick7(currentPage,page_size) {
	$.ajax({
		url: contextPath+'/traffic/getAllFunnelList',
		type : "POST",
		data : {
			page:currentPage,
			pageSize:page_size,
		},
        beforeSend : function(){
            $("#searchFunnel").attr("disabled",true);
        },
        complete :function(){
            $("#searchFunnel").attr("disabled",false);
        },
		success: function (data) {
			if(data != null && data.pageData.list != "" && data.pageData.list != null){
				//新增漏斗按钮显示
				if(data.newFunnelPermission != undefined && data.newFunnelPermission){
					$(".clearfix button").eq(0).show();
				}
				//删除新增漏斗按钮显示
				if(data.deleteFunnelPermission != undefined && data.deleteFunnelPermission){
					$(".clearfix button").eq(1).show();
				}
				if(data.editFunnelPermission == undefined){
					$("#funnelTable thead th:last").remove();
				}
				var page=data.pageData;
				if(page.pages>1){
					$("#page_total").val(page.pages);
					$("#currentPage").val(page.pageNum);
					$("#page_num").val(page.pageNum);
					$("#sp_1_grid-pager")[0].innerText=page.pages;
					$("#view_start_row")[0].innerText= page.startRow;
					$("#view_end_row")[0].innerText= page.endRow;
					$("#view_page_total")[0].innerText= page.total;
					$(".ui-jqgrid").show();
				}else{
					$(".ui-jqgrid").hide();
				}
				var funnelList = data.pageData.list;
				var str = "";
				for(var i=0;i<funnelList.length;i++){
					var newDate = new Date(funnelList[i].createTime);
					var createTime = newDate.format('yyyy-MM-dd h:m:s');
					str += "<tr>"
						+ "<td class='center'><label class='pos-rel'><input type='checkbox' class='ace' value='"+funnelList[i].funnelId+"'><span class='lbl'></span></label></td>"
						+"<td>"+(i+1)+"</td><td><a href=\"javascript:viewFunnel('"+funnelList[i].funnelId+"');\" funnelId='"+funnelList[i].funnelId+"'>"+funnelList[i].name+"</a></td>"
						+"<td>"+funnelList[i].operator+"</td><td>"+createTime+"</td>";
						if(data.editFunnelPermission != undefined && data.editFunnelPermission){
							str += "<td><a class='btn btn-xs btn-primary' role='button' onclick=\"editFunnel('"+funnelList[i].funnelId+"','"+funnelList[i].name+"','"+funnelList[i].funnelType+"')\">编辑</a>"
								+"</td></tr>";
						}
				}
			}else{
				str='<tr><td colspan="12"><div class="alert alert-danger" style="margin-bottom: 0px;text-align: center" role="alert">没有记录!</div></td></tr>';
				$(".ui-jqgrid").hide();
				$("#funnelTable").attr("class","col-xs-12");
				$("#chartDiv").hide();
			}
			$("#funneldData").html("");
			$("#funneldData").html(str);
			if($("#funnelTable th input[type=checkbox]").is(':checked')){
				$("#funnelTable th input[type=checkbox]").attr("checked",false);
			}
			if($("#funnelId").val() != ""){
				viewFunnel($("#funnelId").val());
			}
		}
	});
};

function showPage(param) {
	var endrow = parseInt($("#sp_1_grid-pager")[0].innerText);
	var currentPage = parseInt($("#currentPage").val());
	var page_size = $("#page_size").val();
	var categoryName = $("#categoryName").val();
	if('firstPage'==param) {
		currentPage =1;
	}
	else if('prePage'==param) {
		if(currentPage==1){
			currentPage ==1;
		}else{
			currentPage = currentPage-1;
		}
	}
	else if('nextPage'==param) {
		if(currentPage==endrow){
			currentPage = endrow;
		}else{
			currentPage = currentPage+1;
		}
	} else if('lastPage'==param) {
		currentPage = endrow;
	}
	searchClick7(currentPage,page_size);

}

function deleteFunnel(){
	var funnelIds = [];
	$("input[type=checkbox]:checked").each(function(index){
		funnelIds += $(this).val();
		if($("input[type=checkbox]:checked").length > 1  && index != $("input[type=checkbox]:checked").length-1){
			funnelIds += ",";
		}
	});


	if(funnelIds.length != 0){
		$.ajax({
			url: contextPath + '/traffic/deleteFunnel',
			type: "POST",
			data: {
				"funnelIds": funnelIds
			},
			success: function (data) {
				if(funnelIds.indexOf($("#funnelId").val()) > -1){
					$("#chartDiv").hide();
					$("#funnelTable").attr("class","col-xs-12");
					$("#funnelId").val("");
				}
				searchClick7("1","10");
			}
		});
	}
}

Date.prototype.format=function(fmt) {

	var o = {

		"M+" : this.getMonth()+1, //月份

		"d+" : this.getDate(), //日

		"h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时

		"H+" : this.getHours(), //小时

		"m+" : this.getMinutes(), //分

		"s+" : this.getSeconds(), //秒

		"q+" : Math.floor((this.getMonth()+3)/3), //季度

		"S" : this.getMilliseconds() //毫秒

	};

	var week = {

		"0" : "\u65e5",

		"1" : "\u4e00",

		"2" : "\u4e8c",

		"3" : "\u4e09",

		"4" : "\u56db",

		"5" : "\u4e94",

		"6" : "\u516d"

	};

	if(/(y+)/.test(fmt)){

		fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));

	}

	if(/(E+)/.test(fmt)){

		fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);

	}

	for(var k in o){

		if(new RegExp("("+ k +")").test(fmt)){

			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));

		}

	}

	return fmt;

}

function centerModals() {
	$('.modal').each(
		function(i) {
			var $clone = $(this).clone().css('display', 'block').appendTo('body');
			var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
			top = top > 0 ? top : 0;
			$clone.remove();
			$(this).find('.modal-content').css("margin-top",top-100);
		});
}
$('.modal').on('show.bs.modal', centerModals);
$(window).on('resize', centerModals);